package com.fhy.file_upload.exception;

import com.fhy.file_upload.valueobject.Message;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.multipart.MaxUploadSizeExceededException;
import org.springframework.web.servlet.ModelAndView;

@ControllerAdvice
public class FileUploadExceptionAdvice {
//    @ExceptionHandler(Exception.class)
//    public ModelAndView customException(Exception e) {
//        ModelAndView mv = new ModelAndView();
//        mv.addObject("message", e.getMessage());
//        mv.setViewName("error");
//        return mv;
//    }
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public ResponseEntity<Message> handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
        return ResponseEntity.badRequest().body(new Message("Upload file too large"));
    }
}
